<?php

namespace App\Admin\Controller\Base;


use App\AbstractController;
use App\Admin\Service\Base\RouteService;
use App\Admin\Validate\Base\RouteValidate;
use App\Common\Exception\ApiMessageException;
use App\Common\Util\Response;
use App\Common\Util\TP;

/**
 * 路由控制器
 */
class RouteController extends AbstractController
{

    /**
     * 列表页
     *
     * @return string
     */
    public function lists(): string
    {
        return Response::render('Base/Route/lists');
    }

    /**
     * 列表数据
     *
     * @return \think\Response
     */
    public function listsData(): \think\Response
    {
        return Response::json()->success(RouteService::aop()->lists());
    }


    /**
     * 创建数据页面
     *
     * @return string
     */
    public function create(): string
    {
        return Response::render('Base/Route/edit');
    }


    /**
     * 创建数据
     *
     * @param RouteValidate $validate
     * @return \think\Response
     * @throws ApiMessageException
     */
    public function store(RouteValidate $validate): \think\Response
    {
        RouteService::aop()->store($validate->post());

        return Response::json()->success();
    }

    /**
     * 更新数据页面
     *
     * @return string
     */
    public function edit(): string
    {
        return Response::render('Base/Route/edit');
    }

    /**
     * 更新数据
     *
     * @param RouteValidate $validate
     * @return \think\Response
     * @throws ApiMessageException
     */
    public function update(RouteValidate $validate): \think\Response
    {
        RouteService::aop()->update($validate->post());

        return Response::json()->success();
    }

    /**
     * 删除数据
     *
     * @param RouteValidate $validate
     * @return \think\Response
     * @throws ApiMessageException
     */
    public function destroy(RouteValidate $validate): \think\Response
    {
        RouteService::aop()->destroy($validate->post('ids'));

        return Response::json()->success();
    }

}
